package com.biomatch.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.biomatch.dto.SysLog;
import com.biomatch.dto.SystemLogPagination;
import com.biomatch.mapper.SystemLogMapper;
import com.biomatch.service.SystemLogService;
import com.biomatch.utils.Internationalize;
import com.biomatch.vo.SystemLogVo;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.Signature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class SystemLogServiceImpl implements SystemLogService {

    @Autowired
    private SystemLogMapper systemLogMapper;

    @Autowired
    private Internationalize internationalize;

    @Override
    public IPage<SysLog> getSysLogByPage(SystemLogPagination pagination) {
        QueryWrapper<SysLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("OpeTim", pagination.getStartDate());
        queryWrapper.le("OpeTim", pagination.getEndDate());
        if(!pagination.getType().equals("All")){
            queryWrapper.and(wrapper -> wrapper.eq("type", pagination.getType()));
        }
        queryWrapper.orderByDesc("OpeTim");
        if (!pagination.getLgnnam().equals("")) {
            queryWrapper.and(wrapper -> wrapper.like("LgnNam", pagination.getLgnnam()));
        }
        if (!StringUtils.isEmpty(pagination.getKeywords())) {
            queryWrapper.and(wrapper -> wrapper.like("LgnNam", pagination.getKeywords()).or().like("OpeCat", pagination.getKeywords()));
        }

        IPage<SysLog> iPage = new Page<>(pagination.getCurrent(), pagination.getPageSize());
        return systemLogMapper.selectPage(iPage, queryWrapper);
    }

    @Override
    public void save(Object[] args, Signature signature, Object proceed) {

    }

    @Override
    public List<SystemLogVo> getAllSysLogType() {
        return null;
    }
}